﻿// 首发公众号：洪流学堂
// 作者：大智（微信：zhz11235）

using UnityEngine;
using UnityEngine.XR.ARFoundation;

// 以下位置是真人脸上的位置，注意前置相机是左右镜像状态
// 参考图：https://upload-images.jianshu.io/upload_images/78733-0653b6136bd7cd40.png
public enum FaceAnchor
{
    LeftEyeL = 10796,
    LeftEyeR = 10655,
    RightEyeL = 9218,
    RightEyeR = 9265,
    Nose = 8940,
    MouthL = 10609,
    MouthR = 9103,
}

public static class ARFaceExtensions
{
    /// <summary>
    /// 根据锚点获基于脸部的局部坐标
    /// </summary>
    /// <param name="face"></param>
    /// <param name="anchor"></param>
    /// <returns>face的局部坐标</returns>
    public static Vector3 GetAnchor(this ARFace face, FaceAnchor anchor)
    {
        int index = (int) anchor;
        if (face.vertices.Length > index)
        {
            return face.vertices[index];
        }
        return Vector3.zero;
    }
}

